<html>
<head>
 <title>Wandering flees Trainers</title>
</head>

<body>

<center>
<h1>POI VIII Stage 3 Problem 1</h1>
<h1>Wandering flees Trainers</h1>
</center>

<p>Byteland is known for wandering flee trainers. Tamed flees are taught to
dance. They make precise leaps in the rhythm of music. On the table the trainer
puts in a row numbered coins, but it's not assumed that they are arranged in any
specific order. On each coin there is an inscription of the form &quot;<i>i</i>-&gt;<i>j</i>&quot;;
<i>i </i>is the number of this coin and <i>j</i> is the
number of the coin on which a flee should leap if it sits on this coin. Then the
trainer puts one flee on each coin and turns on the music. The flees, while
dancing, follow the rhythm of the music; i.e. at each beat of
music each flee leaps directly to the coin with number equal to the
j-number
written on the coin it is sitting on. During the dance it may happen that many flees
sit on the
same coin. In this case they continue their performance together. Let's assume
that we have <i>n</i> coins and <i>n</i> flees. As soon as we determine what
inscriptions are on the coins <i>1,2,...,n</i>, we will have the performance fully
determined. However, two different sets of coins may give the same performance,
if only we arrange them in appropriate order.</p>
<h2>Example</h2>
Let us consider the performance on three coins. If the leaps are performed in the
following way: from the first coin to the second one, from the second coin to the third one, from the third coin
to the firs one (we denote this: <i>1-&gt;2,&nbsp;2-&gt;3,&nbsp;3-&gt;1</i>);
then the flees will dance in a circle and no two of them will ever meet on one
coin. For example, the dance <i>1-&gt;2,&nbsp;2-&gt;3,&nbsp;3-&gt;3 </i>is
different, because it will make all the flees meet on the third coin after two beats of music and it will make them jump only on the third coin forever. 
<p>However,&nbsp; the sets <i>1-&gt;2,&nbsp;2-&gt;3,&nbsp;3-&gt;2,&nbsp;4-&gt;4</i>
and <i>1-&gt;1,&nbsp;2-&gt;3,&nbsp;3-&gt;2,&nbsp;4-&gt;3 </i>are of the same
type. If you put these coins in the row - the first set from left to right and
the second from right to left - you would see the same performance.</p>

<h2>Task</h2>
The spectators are discontent if the flees perform in the same way for the
second time. Hence there is needed a program which:
<ul>
  <li>reads from the text file PCH.IN the number of test cases,</li>
  <li>for each case, reads from the file PCH.IN the description of two sets of
    coins and verifies, whether or not, one can arrange the coins from these sets on
    the table in such a way, that flees would give the same performance on both
    sets of coins,</li>
  <li>writes the result into the text file PCH.OUT. </li>
</ul>

<h2>Input</h2>
<p>In the first line of the text file PCH.IN there is written one integer <i>d</i>
equal to the number of test cases, 1&lt;=<i>d</i>&lt;=100. In the following <i>3*d</i>
lines the test cases are described -- each case occupies three consecutive
lines. The first of them contains one integer <i>n</i>, 1&lt;=<i>n</i>&lt;=2
000, equal to the number of coins. Each of the remaining two lines is a description of a set of <i>n</i> coins in a form of <i>n</i> integers from the
interval <i>1...n</i>, separated by single spaces; the <i>i</i>-th integer
denotes the number of a coin that flee must leap to when it seats on the <i>i</i>-th
coin. </p>

<h2>Output</h2>
<p>For each of the test cases from the file PCH.IN your program should write
into the text file PCH.OUT exactly one line containing exactly one letter:</p>
<ul>
  <li>&quot;T&quot; -- if one can arrange on a table the coins from both sets in
    a way, that makes flees perform in the same way,</li>
  <li>&quot;N&quot; -- otherwise.&nbsp; </li>
</ul>

<h2>Sample Input</h2>
<pre>2
3
2 3 1
2 3 3
4
2 3 2 4
1 3 2 3
</pre>

<h2>Sample Output</h2>
<pre>N
T
</pre>

</body>

</html>
